package alvarodelrosal.chat.server.modelo.chataction;

import alvarodelrosal.chat.server.infraestructura.ChatLiveConversations;
import alvarodelrosal.chat.server.modelo.ChatConnection;
import alvarodelrosal.chat.server.modelo.ChatConversation;
import java.util.List;
import java.util.Set;

public class ChatWhoIsIn implements ChatAction {

    @Override
    public String getName() {
        return "WhoIsIn";
    }

    @Override
    public boolean needsAdminPrivileges() {
        return false;
    }

    @Override
    public boolean needsLogin() {
        return true;
    }

    @Override
    public String doAction(ChatConnection currentConnection, List<String> parameters) {
        ChatConversation conversation = ChatLiveConversations.getConversation(Integer.parseInt(parameters.get(0)));
        Set<ChatConnection> connections = conversation.getConnections();
        StringBuilder builder = new StringBuilder("WhoIsIn<:@:>");
        builder.append(parameters.get(0));
        for(ChatConnection connection : connections) {
            builder.append("<:@:>");
            builder.append(connection.whoAmI().getUserId());
        }
        return builder.toString();
    }
    
}
